﻿using System;
using System.Text;
using System.Linq;
using System.Linq.Expressions;
using System.Text.Json;
using System.Diagnostics;
using System.Collections.Generic;
using System.Threading.Tasks;
using System.Reflection;
using System.Data.Common;
using Fast.Framework.Interfaces;
using Fast.Framework.Extensions;
using Fast.Framework.Models;
using Oracle.ManagedDataAccess.Client;
using MySqlConnector;
using Npgsql;
using System.Data.SQLite;
using System.Data.SqlClient;
using System.ComponentModel.DataAnnotations;

namespace Fast.Framework.Test
{
    public class Program
    {
        static async Task Main(string[] args)
        {
            try
            {
                #region 数据库选项
                var options = new DefaultDbOptions()
                {
                    DbType = DbType.SQLServer,
                    ProviderName = "System.Data.SqlClient",
                    FactoryName = "System.Data.SqlClient.SqlClientFactory,System.Data",
                    ConnectionStrings = "server=localhost;database=Test;user=sa;pwd=123456789;min pool size=3;max pool size=100;connect timeout =30;"
                };

                //var options = new DefaultDbOptions()
                //{
                //    DbType = DbType.MySQL,
                //    ProviderName = "MySqlConnector",
                //    FactoryName = "MySqlConnector.MySqlConnectorFactory,MySqlConnector",
                //    ConnectionStrings = "server=localhost;database=Test;user=root;pwd=123456789;port=3306;min pool size=3;max pool size=100;connect timeout =30;AllowLoadLocalInfile=True;"
                //};

                //var options = new DefaultDbOptions()
                //{
                //    DbType = DbType.PostgreSQL,
                //    ProviderName = "Npgsql",
                //    FactoryName = "Npgsql.NpgsqlFactory,Npgsql",
                //    ConnectionStrings = "host=localhost;database=test;userid=postgres;pwd=123456789;port=5432;"
                //};

                //var options = new DefaultDbOptions()
                //{
                //    DbType = DbType.Oracle,
                //    ProviderName = "Oracle.ManagedDataAccess.Client",
                //    FactoryName = "Oracle.ManagedDataAccess.Client.OracleClientFactory,Oracle.ManagedDataAccess",
                //    ConnectionStrings = "data source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=localhost)(PORT=1521)))(CONNECT_DATA=(SERVICE_NAME=ORCL)));user id=system;password=Oracle2022;min pool size=3;max pool size=100;connect timeout =30;"
                //};

                //var options = new DefaultDbOptions()
                //{
                //    DbType = DbType.SQLite,
                //    ProviderName = "System.Data.SQLite",
                //    FactoryName = "System.Data.SQLite.SQLiteFactory,System.Data.SQLite",
                //    ConnectionStrings = "data source=mysqlite.db;pooling=true;"
                //};
                #endregion

                var ado = new Ado<DefaultDbOptions>(options);//原生Ado
                var db = new DbContext<DefaultDbOptions>(ado);//数据库上下文

                db.Ado.DbLog = (sql, parameters) =>
                  {
                      Console.WriteLine($"ExecuteSql：{sql}");
                      if (parameters != null)
                      {
                          foreach (var item in parameters)
                          {
                              Console.WriteLine($"参数名:{item.ParameterName} 参数值:{item.Value}");
                          }
                      }
                      Console.WriteLine($"ExecuteTime：{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")}");
                      Console.WriteLine();
                  };

            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            Console.ReadKey();
        }
    }
}